package edu.xlh.travel.controller.admin;

import com.alibaba.fastjson.JSONArray;
import edu.xlh.travel.common.Result;
import edu.xlh.travel.pojo.CheckingTask;
import edu.xlh.travel.pojo.querypojo.QueryCheckTask;
import edu.xlh.travel.service.CheckingTaskService;
import edu.xlh.travel.syslog.annontion.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Controller
@CrossOrigin
@RequestMapping("/checkingTask")
public class CheckingTaskController {
    @Autowired
    private CheckingTaskService checkingTaskService;

    @Log("跳转待审核任务列表页面")
    @RequestMapping("/checkingTaskList")
    public String checkingList() {
        return "admin/checkTaskmanage/checkingList";
    }

    @Log("待审核任务列表查询")
    @RequestMapping("/findAllCheckingTask")
    @ResponseBody
    public Result findAllCheckingTask(int page, int limit , HttpSession session) {
        return checkingTaskService.findAllCheckingTask(page , limit , session);
    }

    @Log("审核通过")
    @RequestMapping("/agree")
    @ResponseBody
    public Result agree(@RequestBody CheckingTask checkingTask , HttpSession session) {
        return checkingTaskService.agree(checkingTask , session);
    }

    @Log("审核拒绝")
    @RequestMapping("/reject")
    @ResponseBody
    public Result reject(@RequestBody CheckingTask checkingTask , HttpSession session) {
        return checkingTaskService.reject(checkingTask , session);
    }

    //@Log("取消订单")
    @RequestMapping("/cancelOrder")
    @ResponseBody
    public Result cancelOrder(String orderId ,String orderType , HttpSession session) {
        return checkingTaskService.cancelOrder(orderId , orderType ,session);
    }

    /*
     * query checkingTask by condition
     * */
    @Log("条件模糊查询已审核任务")
    @RequestMapping("/QueryCheckingTaskByCondition")
    @ResponseBody
    public Result  QueryCheckingTaskByCondition(Integer page, Integer limit, QueryCheckTask queryCheckingTask , HttpSession session) {
        return checkingTaskService.QueryCheckingTaskByCondition(page , limit ,queryCheckingTask , session);
    }

    /*
     * delete CheckingTask and CheckedTask by id
     * */
    @Log("根据id删除已审核任务")
    @RequestMapping("/deleteById/{id}")
    @ResponseBody
    public Result deleteById(@PathVariable("id") String id , @RequestBody HashMap hashMap , HttpSession session) {
        return checkingTaskService.deleteById(id , hashMap , session);
    }

    /*
     *
     * batch delete
     *  */
    @Log("批量删除已审核任务")
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Result batchDelete(@RequestBody JSONArray jsonArray , String taskType ,  HttpSession session) {
        return checkingTaskService.batchDelete(jsonArray ,taskType , session);
    }

}
